const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.RigidBody)
    fruit_body: cc.RigidBody = null

    // 爆炸音效
    @property(cc.AudioClip)
    music_boom: cc.AudioClip = null

    // 水音效
    @property(cc.AudioClip)
    music_water: cc.AudioClip = null

    // 碰撞音效
    @property(cc.AudioClip)
    music_knock: cc.AudioClip = null

    drop() { 
        this.fruit_body.gravityScale = 1
        this.fruit_body.linearVelocity = cc.v2(10, -480)
    }

    onLoad() { 

    }

    onBeginContact(contact, self, other) { 
        // 播放碰撞声音
        cc.audioEngine.play(this.music_knock, false, 1)
        if (self.node._name == other.node._name) { 
            self.node.emit('sameContact', { self, other });
            // 播放碰撞声音
            cc.audioEngine.play(this.music_water, false, 1)
        }
    }

    // 结束碰撞
    onEndContact() { 

    }

    // 持续碰撞，接触时被调用
    onPreSolve() { 

    }

    // 碰撞接触更新完后调用，可以获得冲量信息
    onPostSolve() { 

    }


}
